Page({
    data: {
        userInfo: {},
        activeTab: 0,
        orders: []
    },

    onLoad() {
        this.loadUserInfo();
        this.loadOrders();
    },

    loadUserInfo() {
        // 模拟用户数据
        const mockUserInfo = {
            avatar: '/images/avatar.jpg',
            nickName: '回收达人',
            phone: '138****8888'
        };
        this.setData({ userInfo: mockUserInfo });
    },

    loadOrders() {
        // 模拟订单数据
        const mockOrders = [
            {
                id: 1,
                orderNo: 'REC20230001',
                categoryName: '废纸类',
                weight: 12.5,
                price: 45.80,
                createTime: '2023-06-15 14:30',
                status: 1,
                statusText: '待接单'
            },
            {
                id: 2,
                orderNo: 'REC20230002',
                categoryName: '塑料类',
                weight: 8.2,
                price: 32.80,
                createTime: '2023-06-10 09:15',
                status: 3,
                statusText: '已完成'
            }
        ];
        this.setData({ orders: mockOrders });
    },

    onTabChange(e) {
        this.setData({ activeTab: e.detail.name });
        this.loadOrders(); // 根据tab重新加载订单
    },

    viewOrderDetail(e) {
        const id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: `/pages/order/detail?id=${id}`
        });
    },

    contactService(e) {
        e.stopPropagation(); // 阻止事件冒泡
        wx.makePhoneCall({
            phoneNumber: '4008888888'
        });
    }
});